// 路径为: '@/apis/goods'
import axiosInstance from "./axiosInstance";

// 获取所有商品分类
export const getGoodsCategories = () => {
    return axiosInstance.get("/get/categories");
};

// 获取所有商品
export const getGoods = () => {
    return axiosInstance.get("/get/goods");
};

// 搜索商品
export const searchProducts = (query, categoryId) => {
    return axiosInstance.get("/api/products/search", {
        params: { query, categoryId }
    });
};

// 根据ID获取商品
export const getProductById = (id) => {
    return axiosInstance.get(`/api/products/${id}`);
};

// 添加新商品
export const addProduct = (productData) => {
    return axiosInstance.post("/api/products", productData);
};

// 更新商品信息
export const updateProduct = (id, productData) => {
    return axiosInstance.put(`/api/products/${id}`, productData);
};

// 更新商品库存
export const updateProductStock = (id, newStockQuantity) => {
    return axiosInstance.patch(`/api/products/${id}/stock`, null, {
        params: { newStockQuantity }
    });
};

// 删除商品
export const deleteProduct = (id) => {
    return axiosInstance.delete(`/api/products/${id}`);
};

// 根据分类ID获取商品
export const getProductsByCategoryId = (categoryId) => {
    return axiosInstance.get(`/api/products/category/${categoryId}`);
};